package com.example.a2022application.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.a2022application.BaseActivity;
import com.example.a2022application.R;
import com.example.a2022application.bean.RegisterBean;
import com.example.a2022application.net.Urls;
import com.example.a2022application.utils.SpUtils;
import com.example.a2022application.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import androidx.annotation.Nullable;

public class CreateClassActivity extends BaseActivity implements View.OnClickListener {
    private TextView tv_create;
    private EditText et_name;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_createclass);
        tv_create = findViewById(R.id.tv_create);
        et_name = findViewById(R.id.et_name);
        tv_create.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tv_create:
                String name = et_name.getText().toString();
                if (TextUtils.isEmpty(name)){
                    ToastUtil.showToast("请输入班级名称");
                    return;
                }
                OkGo.<String>post(Urls.CREATECLASS)
                        .params("className",name)
                        .execute(new StringCallback() {
                            @Override
                            public void onSuccess(Response<String> response) {
                                RegisterBean bean = getGson().fromJson(response.body(),RegisterBean.class);
                                if (bean.getCode() == 0){
                                    finish();
                                }
                                ToastUtil.showToast(bean.getMessage());
                            }
                        });

                break;

        }
    }
}
